/*
* Copyright 2009 NOR_/D Labs <http://labs.nortd.com>
*
* This file is part of SceneExpression.
* SceneExpression is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License 
* as published by the Free Software Foundation, either version 3 of 
* the License, or (at your option) any later version. For details
* see <http://www.gnu.org/licenses/>.
*
* * *
* 
*/

#ifndef SX_CHECKBOX
#define SX_CHECKBOX


#include <sx/Widget.h>
#include <osg/Timer>

namespace sx {

class CheckboxWidget;
class Shape;


class CheckboxNob : public Widget {
    public:
        bool _bChecked;     
        osg::ref_ptr<CheckboxWidget> _checkbox;
        osg::ref_ptr<Shape>    _checkshape;
        osg::Timer _flipTimer;
        bool _bAnimate;
        bool _bFlipping;
        float _flipAngle;
        bool _bReached90deg;        
    
        CheckboxNob( CheckboxWidget* checkbox );
        
        void setValue( bool checked );
        
        void reshape();
        void update();
    
        // touch events return false and "bubble up" to Checkbox
        bool touchDown( Touch& touch ){return false;}
        bool touchMove( Touch& touch ){return false;}
        bool touchUp( Touch& touch ){return false;}    
};



class CheckboxWidget : public Widget {
    public:
  
        CheckboxWidget();
        ~CheckboxWidget();
        
        void setValue( bool checked );        
        bool getValue();        
        void setLabelColor( float r, float g, float b, float a );        
        void addEventHandler( CheckboxHandler* handler );
        std::vector<CheckboxHandler*>&  getEventHandlers();
        
        virtual void reshape();
//        void update(){}      
                
        // Events
        //
        bool touchDown( Touch& touch );
        bool touchMove( Touch& touch );
        bool touchUp( Touch& touch );
            
            
    protected:
        CheckboxNob* _nob;
        std::string _defaultTypeface;  
        osg::ref_ptr<osgText::Text>   _label;    
        std::vector<CheckboxHandler*> _handlers;
        osg::Vec4 _buttonPressBorderColor;
        osg::Vec4 _buttonPressBorderColorTemp;
};


}
#endif